<?php include_once "top.php";
if(trim($_GET['sdate']) && trim($_GET['edate'])){
	$stime=strtotime($_GET['sdate']);
	$etime=strtotime($_GET['edate'])+86400;
	$res=$db->ig2_query_select('select `mae_shop`.name,count(*) as count from `mae_shop`,`mae_role`,`mae_sell` where `mae_sell`.uid=`mae_role`.uid and `mae_role`.shop_id=`mae_shop`.id and `mae_sell`.create_time >= '.$stime.' and `mae_sell`.create_time < '.$etime.' group by `mae_shop`.name ORDER BY COUNT DESC');
}
?>
<div class="addleft">
	<a href="city_ranking.php">城市销量排名</a>
	<a href="shop_ranking.php">店铺销量排名</a>
</div>
<script language="javascript">
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function checkForm(){
	var sdate=trim($('#sdate').val());
	var edate=trim($('#edate').val());
	if(sdate==''){
		alert('请选择开始日期');
		return false;
	}
	if(edate==''){
		alert('请选择结束日期');
		return false;
	}
	return true;
}
</script>
<div class="addbar">
	<ul>
	<h2 style="float:left">店铺销量排名</h2>
	<div style="float:left;margin:20px 0 0 20px">
		<form action="shop_ranking.php" method="get" onsubmit="return checkForm()">
		<input id="sdate" type="text" name="sdate" value="<?php echo $_GET['sdate']?>" class="laydate-icon ipt" onclick="laydate()" placeholder="选择开始日期" style="width:150px" /> -
		<input id="edate" type="text" name="edate" value="<?php echo $_GET['edate']?>" class="laydate-icon ipt" onclick="laydate()" placeholder="选择结束日期" style="width:150px" />
		<input type="submit" name="sub_sch" value="查找" />
		</form>
	</div>

	<li style="border:none">1.计算量较大，点击查找后请耐心等待，请勿多次点击查找按钮。</li>
	<li style="border:none">2.计算时对服务器负载较大，可能会引起前端使用运行缓慢，请尽量选择非高峰时段查询。</li>
	<li>3.仅显示销量不为零的店铺。</li>
	<?php if(trim($_GET['sdate']) && trim($_GET['edate'])){?>
	<li class="lihd"><strong align="center">
		<label>排名</label>
		<label style="width:500px">店铺名称</label>
		<label>销量</label>
		</strong>
	</li>
	<?php foreach($res as $k=>$v){?>
	<li align="center">
		<label><?php echo $k+1?></label>
		<label style="width:500px"><?php echo $v['name']?></label>
		<label><?php echo $v['count']?></label>
	</li>
	<?php }?>
	<?php }?>
	</ul>
</div>
<?php include_once "down.php";?>